package handler

import (
	"context"
	. "rbac/models"
	pb "rbac/proto/rbacLogin"
)

type RbacLogin struct{}

// 后台用户登录的微服务
func (e *RbacLogin) Login(ctx context.Context, req *pb.LoginRequest, res *pb.LoginResponse) error {
	var manage Manager
	err := DB.Where("username = ? AND password = ?", req.Username, req.Password).Take(&manage).Error
	if manage.ID == 0 {
		res.IsLogin = false
		return err
	}
	// 处理数据
	var tempList []*pb.ManagerModel
	tempList = append(tempList, &pb.ManagerModel{
		Id:       int64(manage.ID),
		Username: manage.Username,
		Password: manage.Password,
		Mobile:   manage.Mobile,
		Email:    manage.Email,
		Status:   int64(manage.Status),
		RoleId:   int64(manage.RoleID),
		AddTime:  int64(manage.AddTime),
		IsSuper:  int64(manage.IsSuper),
	})
	res.IsLogin = true
	res.UserList = tempList
	return nil
}
